import OSS from 'ali-oss';
import { Message } from 'element-ui';
const accessKeyId = 'LTAI4G16hbbzifxqaJ5kwx5i';
const accessKeySecret = 'FgacDnyjRBurkCfsUXONUkUaXpfSTU';
const region = 'oss-cn-beijing';
// hopermall

const client = new OSS({
  region,
  accessKeyId,
  accessKeySecret,
  // stsToken: '',
  bucket: 'fitbar',
  // secure: true
});

// 简单上传
const simpleUpload = function (file, callback) {
  let name = `DUDU${Date.now()}${Math.floor(Math.random() * 1000)}`;
  // let name = 'file';
  client.put(name, file)
  .then(res => {
    callback(res)
  })
  .catch(e => {
    callback(e)
  })
};
const multipartUpload = function (file, callback) {
  let name = `DUDU${Date.now()}${Math.floor(Math.random() * 1000)}`;
  client.multipartUpload(name, file)
  .then(res => {
    callback(res)
  })
  .catch(e => {
    console.log(e)
    Message.error('上传失败')
  })
}
const multipleUpload = function () {

}

export {
  client, simpleUpload, multipartUpload
}
